from datetime import datetime
from typing import Optional
from uuid import UUID, uuid4

from sqlmodel import SQLModel, Field

IdType = UUID

class SQLBaseModel(SQLModel):
    """
    公共 ORM 模型，基表
    """

    __abstract__ = True

    id: IdType = Field(
        default_factory=uuid4,
        primary_key=True,
        index=True,
        nullable=False,
        description="ID",
    )

    create_datetime: datetime = Field(
        default_factory=datetime.now, index=True, description="创建时间"
    )
    update_datetime: Optional[datetime]= Field(
        default_factory=datetime.now,
        sa_column_kwargs={"onupdate": datetime.now},
        description="更新时间",
    )

    is_delete: bool = Field(default=False, index=True, description="假删除")
